package com.itheima.dao;

import com.itheima.domain.Classes;
import com.itheima.domain.Student;
import org.apache.ibatis.annotations.One;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface StudentDao {

    @Results({

            @Result(column = "id",property = "id",id = true),
            @Result(column = "name",property = "name"),
            @Result(column = "age",property = "age"),

            @Result(
                    property = "classes",
                    javaType = Classes.class,
                    column = "cid",
                    one = @One( select = "com.itheima.dao.ClassesDao.findByCid")
            )
    })
    @Select("select * from student")
    List<Student> findAll();

    @Select("SELECT s.* FROM stu_cr sc ,student s WHERE sc.sid = s.id AND sc.cid = #{id}")
    List<Student> findById(Integer id);

}
